package com.shen.add;

import java.util.concurrent.CountDownLatch;

/**
 *
 */
public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {
        /**
         *    public CountDownLatch(int count) {
         *         if (count < 0) throw new IllegalArgumentException("count < 0");  //给定的count必须大于或等于0
         *         this.sync = new Sync(count);
         *     }
         */
        //6
        CountDownLatch countDownLatch=new CountDownLatch(6);

        for (int i = 0; i < 6; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"Go Out");
                countDownLatch.countDown();//-1
            }).start();
        }
       countDownLatch.await();//等待计数器归零，然后再向下进行

        System.out.println("输出完毕！");
        /**
         * Thread-0Go Out
         * Thread-3Go Out
         * Thread-2Go Out
         * Thread-1Go Out
         * Thread-5Go Out
         * Thread-4Go Out
         * 输出完毕！
         */

    }

}
